package cronjob

import (
	"context"
	"github.com/jinzhu/copier"
	"go-zero-admin/application/job/rpc/pb"

	"go-zero-admin/application/job/api/internal/svc"
	"go-zero-admin/application/job/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SearchCronInfoByIdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 查询定时任务根据id
func NewSearchCronInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchCronInfoByIdLogic {
	return &SearchCronInfoByIdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SearchCronInfoByIdLogic) SearchCronInfoById(req *types.SearchCronByIdReq) (resp *types.SearchCronByIdRes, err error) {
	res, err := l.svcCtx.JobCronSvc.GetCronInfo(l.ctx, &pb.GetCronInfoReq{TaskId: uint32(req.TaskId)})
	if err != nil {
		return nil, err
	}
	resp = &types.SearchCronByIdRes{}

	_ = copier.Copy(resp, res)

	return resp, nil
}
